package com.chen.apply.controller;

import com.chen.apply.service.ReimburseService;
import com.common.pojo.req.ReimburseSubmitReqDTO;
import com.common.pojo.req.ReimburseUpdateReqDTO;
import com.common.pojo.resp.ReimburseEditRespDTO;
import com.common.pojo.resp.ReimburseManageRespDTO;
import com.common.pojo.resp.ReimburseShowRespDTO;
import com.common.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/reimburse")
public class ReimburseController {
    @Autowired
    private ReimburseService reimburseService;

    @GetMapping("/show/{applyId}")
    public Result<List<ReimburseShowRespDTO>> getReimburseShowRespDTO(@PathVariable Integer applyId) {
        List<ReimburseShowRespDTO> result = reimburseService.getReimburseShowRespDTO(applyId);
        return Result.success(result);
    }

    @PostMapping("/save")
    public  Result<Boolean> submitReimburse(@RequestBody ReimburseSubmitReqDTO reimburseSubmitReqDTO) {
        boolean result = reimburseService.submitReimburse(reimburseSubmitReqDTO);
        return Result.success(result);
    }

    @GetMapping("/manage/{userId}")
    public Result<List<ReimburseManageRespDTO>> getReimburseManageRespDTO(@PathVariable Integer userId) {
        List<ReimburseManageRespDTO> result = reimburseService.getReimburseManageRespDTO(userId);
        return Result.success(result);
    }

    @GetMapping("/edit/{id}")
    public Result<ReimburseEditRespDTO> getReimburseEditData(@PathVariable Integer id) {
        ReimburseEditRespDTO result = reimburseService.getReimburseEditData(id);
        return Result.success(result);
    }

    @DeleteMapping("/delete/{id}")
    public Result<Boolean> deleteReimburse(@PathVariable Integer id) {
        boolean result = reimburseService.deleteReimburse(id);
        return Result.success(result);
    }

    @PutMapping("/update")
    public Result<Boolean> updateReimburse(@RequestBody ReimburseUpdateReqDTO reimburseUpdateReqDTO) {
        boolean result = reimburseService.updateReimburse(reimburseUpdateReqDTO);
        return Result.success(result);
    }

    @PutMapping("/submit/{id}")
    public Result<Boolean> submitReimburse(@PathVariable Integer id) {

        boolean b = reimburseService.changeReimburseState(id);
        return Result.success(true);
    }

}
